package PrintAlternately;

import java.util.concurrent.locks.LockSupport;

/**
 * Created with IntelliJ IDEA.
 * Description: 使用park unpark 来解决先2后1
 * User: sfx
 * Date: 2022-12-28
 * Time: 10:16
 */
public class TestDemo3 {
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            LockSupport.park();
            System.out.println("1");
        });
        t1.start();

        Thread t2 = new Thread(()->{
            System.out.println("2");
            LockSupport.unpark(t1);
        });
        t2.start();
    }

}
